﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace LabelPrintSystem
{
    public partial class FrmLogin : Form
    {
        ClsDataUser user;
        public FrmLogin(ClsDataUser user0, string name = "账号登录")
        {
            InitializeComponent();
            this.Text = name;
            if(ClsDifinition.RUNNING_MODE==1) this.Text+="(诺基亚车间)";
            else this.Text += "(天线车间)";
            this.user = user0;
            this.MaximizeBox = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.KeyPreview = true;//keypress 优先触发form  keypress
            this.txt_userpsw.PasswordChar = Convert.ToChar("*");
        }

        private void FrmLogin_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                btn_ok.PerformClick();
            }
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            if (!user.verifyUser(txt_userid.Text.Trim(), txt_userpsw.Text.Trim()))
            {
                MessageBox.Show(user.sError);
                return;
            }
            this.DialogResult = DialogResult.OK;
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        private void FrmLogin_Shown(object sender, EventArgs e)
        {
            this.txt_userid.Focus();
        }
    }
}
